/**
 * 
 */
package com.pactera.android.adapter;

import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.pactera.android.R;
import com.pactera.android.db.ContactListDB;

/**
 * @author David Zheng
 *
 */
public class ContactListAdapter extends CursorAdapter {
	
	static final String TAG = "ContactListAdapter";
	
	private LayoutInflater inflater;

	@SuppressWarnings("deprecation")
	public ContactListAdapter(Context context, Cursor c) {
		super(context, c);
		inflater = LayoutInflater.from(context);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		Log.d(TAG, "bindView");
		if (null == cursor) return;
		TextView name = (TextView)view.findViewById(R.id.contact_row_name);
		TextView number = (TextView)view.findViewById(R.id.contact_row_num);
		Log.d(TAG, "name:"+cursor.getString(cursor.getColumnIndex(ContactListDB.NAME)));
		Log.d(TAG, "mobile:"+cursor.getString(cursor.getColumnIndex(ContactListDB.MOBILE)));
		name.setText(cursor.getString(cursor.getColumnIndex(ContactListDB.NAME)));
		number.setText(cursor.getString(cursor.getColumnIndex(ContactListDB.MOBILE)));
		
		view.setTag(cursor.getString(cursor.getColumnIndex(ContactListDB.MOBILE)));		
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		Log.d(TAG, "new View");
		View view = inflater.inflate(R.layout.contact_row, parent, false);
		
		return view;
	}
	
	

	

}
